import { defineStore } from 'pinia'
import {
  reqC1Category,
  reqC2Category,
  reqC3Category,
} from '../../api/product/attr'
import type { CateResponseData } from '../../api/product/attr/type' // 引入类型定义
import type { CateStore } from './types/type'

const useCategoryStore = defineStore('category', {
  state: (): CateStore => {
    return {
      cate1List: [],
      cate2List: [],
      cate3List: [],
      c1Id: '',
      c2Id: '',
      c3Id: '',
    }
  },
  actions: {
    async getC1() {
      let res: CateResponseData = await reqC1Category()
      if (res.code === 200) {
        this.cate1List = res.data
      }
    },
    async getC2() {
      let res: CateResponseData = await reqC2Category(this.c1Id)
      if (res.code === 200) {
        console.log(2222)
        this.cate2List = res.data
      }
    },
    async getC3() {
      let res: CateResponseData = await reqC3Category(this.c2Id)
      if (res.code === 200) {
        console.log(2222)
        this.cate3List = res.data
      }
    },
  },
  getters: {},
})

export default useCategoryStore
